/*********************************************************
          File Name:template_type_argument.cpp
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Sat 12 Dec 2015 12:04:39 PM CST
**********************************************************/

#include <iostream>
#include <string.h>

using std::cout;
using std::endl;

// template type

template<typename T>
int cmp(const T &a, const T &b)
{
        if(a > b)
                return 1;
        if(b > a)
                return -1;

        return 0;
}

// template argument

template<size_t N, size_t M>
int s_cmp(const char (&a)[N], const char (&b)[M])
{
        return strcmp(a, b);
}

// template argument and template type

template<typename T, size_t N>
auto size(const T (&a)[N]) -> decltype(N)
{
        return N;
}

int main(void)
{
        cout << cmp(1, 2) << endl;
        cout << cmp(0.3, 0.2) << endl;

        const char a[] = "this";
        const char b[] = "that";

        cout << s_cmp(a, b) << endl;

        cout << "size of '" << a << "' is " << size(a) << endl;
}
